<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改上传课件')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-file-edit" th:object="${ycCoursewareFile}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">课件名称：</label>
                <div class="col-sm-8">
                    <input name="coursewareName" th:field="*{coursewareName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">学科类型：</label>
                <div class="col-sm-8">
                    <textarea name="coursewarePrimary" class="form-control">[[*{coursewarePrimary}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">课件文件：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="coursewareFile" th:field="*{coursewareFile}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="coursewareFile" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">课件图标：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="coursewareIcon" th:field="*{coursewareIcon}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="coursewareIcon" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">上传人：</label>
                <div class="col-sm-8">
                    <input name="coursewareUser" th:field="*{coursewareUser}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">文件状态：</label>
                <div class="col-sm-8">
                    <select name="fileState" class="form-control m-b" th:with="type=${@dict.getType('sys_resource_state')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{fileState}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">上传时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="fileTime" th:value="${#dates.format(ycCoursewareFile.fileTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "system/file";
        $("#form-file-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-file-edit').serialize());
            }
        }

        $("input[name='fileTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });
    </script>
</body>
</html>